package pl.skubicha.utils;

import java.util.ArrayList;
import java.util.List;

import pl.skubicha.domain.Groups;
import pl.skubicha.response.GroupDTO;

public class GroupMapper {

	public static GroupDTO map( final Groups group ) {
		final GroupDTO dto = new GroupDTO();
		dto.setId( group.getId() );
		dto.setGroupName( group.getGroupName() );
		dto.setNumericGroupName( group.getNumericGroupName() );
		dto.setUsers( group.getUsers() );
		dto.setSubjects( group.getSubjects() );

		return dto;
	}

	public static Groups map( final GroupDTO dto ) {
		final Groups group = new Groups();
		group.setId( dto.getId() );
		group.setGroupName( dto.getGroupName() );
		group.setNumericGroupName( dto.getNumericGroupName() );
		group.setUsers( dto.getUsers() );
		group.setSubjects( dto.getSubjects() );

		return group;
	}

	public static List< GroupDTO > map( final Iterable< Groups > groups ) {
		return mapPages( groups );
	}

	private static List< GroupDTO > mapPages( final Iterable< Groups > groups ) {
		final List< GroupDTO > dtos = new ArrayList< GroupDTO >();

		for ( final Groups group : groups ) {
			dtos.add( map( group ) );
		}

		return dtos;
	}
}
